﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace MO
{
    public class DbOperation
    {
        static IDbOperation db;
        public static IDbOperation DB
        {
            get
            {
                if (db == null)
                {
                    db = CreateDB();
                }
                return db;
            }
        }
        public static IDbOperation CreateDB()
        {
            return CreateDB(DBConfig.GetConfig());
        }
        public static IDbOperation CreateDB(DBConfig config)
        {
            IDbOperation idb = null;
            if (config.DbType == DataBaseType.SqlServer)
                idb = new SqlDbOperation(config.GetConnection());
            else if (config.DbType == DataBaseType.MySql)
                idb = new MySqlDbOperation(config.GetConnection());
            return idb;
        }
        public static void Dispose()
        {
            if (db != null)
            {
                db.Dispose();
                db = null;
            }
        }
    }
}
